package com.lorenzogao.componentbased;

import android.app.Application;

import com.lorenzogao.componentlib.AppConfig;
import com.lorenzogao.componentlib.IAppComponet;

/**
 * Created by GanLanPing
 * data:2019/3/2
 * time:14:49
 * 邮箱:2508719070@qq.com
 * Description:
 */

public class MainApp extends Application implements IAppComponet {


    private static MainApp application;


    public static MainApp getApplication(){
        return  application;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        initializa(this);
    }

    @Override
    public void initializa(Application application) {
        for (String component: AppConfig.COMPONENTS){
            try {
                Class<?> clazz=Class.forName(component);
                Object object=clazz.newInstance();
                if (object instanceof IAppComponet){
                ((IAppComponet) object).initializa(this);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }
}
